home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu619.dms
/
pu619.adf
/
Utilities
/
TASKE.LHA
/
Source
/
TaskE.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-26
|
7KB
|
277 lines
/*
* Source machine generated by GadToolsBox V2.0b
* which is (c) Copyright 1991-1993 Jaba Development
*
* GUI Designed by : Michael D. Bayne
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include <clib/diskfont_protos.h>
#include "TaskE.h"
struct Screen *Scr = NULL;
UBYTE *PubScreenName = NULL;
APTR VisualInfo = NULL;
struct Window *TaskEWnd = NULL;
struct Gadget *TaskEGList = NULL;
struct Menu *TaskEMenus = NULL;
struct IntuiMessage TaskEMsg;
struct Gadget *TaskEGadgets[4];
UWORD TaskELeft = 0;
UWORD TaskETop = 12;
UWORD TaskEWidth = 363;
UWORD TaskEHeight = 89;
UBYTE *TaskEWdt = (UBYTE *)"Task Exchange";
struct TextAttr *Font, Attr;
UWORD FontX, FontY;
UWORD OffX, OffY;
struct TextFont *TaskEFont = NULL;
struct NewMenu TaskENewMenu[] = {
NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)"About...", (STRPTR)"?", 0, 0L, (APTR)TaskEABOUT,
NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)TaskEQUIT,
NM_TITLE, (STRPTR)"Kill", NULL, 0, NULL, NULL,
NM_ITEM, (STRPTR)"Window...", (STRPTR)"W", 0, 0L, (APTR)TaskEKWND,
NM_ITEM, (STRPTR)"Screen...", (STRPTR)"S", 0, 0L, (APTR)TaskEKSCR,
NM_END, NULL, NULL, 0, 0L, NULL };
UWORD TaskEGTypes[] = {
LISTVIEW_KIND,
BUTTON_KIND,
LISTVIEW_KIND,
BUTTON_KIND
};
struct NewGadget TaskENGad[] = {
184, 2, 176, 72, NULL, NULL, GD_TASKL, 0, NULL, (APTR)TASKLClicked,
4, 72, 176, 15, (UBYTE *)"_Reboot the machine", NULL, GD_REBOOT, PLACETEXT_IN, NULL, (APTR)REBOOTClicked,
4, 2, 176, 72, NULL, NULL, GD_SCREENL, 0, NULL, (APTR)SCREENLClicked,
184, 72, 176, 15, (UBYTE *)"_Update Task List", NULL, GD_UPDATE, PLACETEXT_IN, NULL, (APTR)UPDATEClicked
};
ULONG TaskEGTags[] = {
(TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(TAG_DONE),
(GT_Underscore), '_', (TAG_DONE)
};
static UWORD ComputeX( UWORD value )
{
return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
}
static UWORD ComputeY( UWORD value )
{
return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
}
static void ComputeFont( UWORD width, UWORD height )
{
Forbid();
Font = &Attr;
Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
FontX = GfxBase->DefaultFont->tf_XSize;
Permit();
OffX = Scr->WBorLeft;
OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
if ( width && height ) {
if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
goto UseTopaz;
if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
goto UseTopaz;
}
return;
UseTopaz:
Font->ta_Name = (STRPTR)"topaz.font";
FontX = FontY = Font->ta_YSize = 8;
}
int SetupScreen( void )
{
if ( ! ( Scr = LockPubScreen( PubScreenName )))
return( 1L );
ComputeFont( 0, 0 );
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
return( 0L );
}
void CloseDownScreen( void )
{
if ( VisualInfo ) {
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
}
int HandleTaskEIDCMP( void )
{
struct IntuiMessage *m;
struct MenuItem *n;
int (*func)();
BOOL running = TRUE;
while( m = GT_GetIMsg( TaskEWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&TaskEMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( TaskEMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( TaskEWnd );
GT_EndRefresh( TaskEWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = TaskECloseWindow();
break;
case IDCMP_ACTIVEWINDOW:
running = TaskEActiveWindow();
break;
case IDCMP_VANILLAKEY:
running = TaskEVanillaKey();
break;
case IDCMP_GADGETUP:
case IDCMP_GADGETDOWN:
func = ( void * )(( struct Gadget * )TaskEMsg.IAddress )->UserData;
running = func();
break;
case IDCMP_MENUPICK:
while( TaskEMsg.Code != MENUNULL ) {
n = ItemAddress( TaskEMenus, TaskEMsg.Code );
func = (void *)(GTMENUITEM_USERDATA( n ));
running = func();
TaskEMsg.Code = n->NextSelect;
}
break;
}
}
return( running );
}
int OpenTaskEWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = TaskELeft, wtop = TaskETop, ww, wh;
ComputeFont( TaskEWidth, TaskEHeight );
ww = ComputeX( TaskEWidth );
wh = ComputeY( TaskEHeight );
wleft = ( Scr->Width - ww )/2 - Scr->WBorRight;
wtop = ( Scr->Height - wh - Scr->WBorTop - Scr->WBorBottom - Font->ta_YSize - 1 )/2;
if ( ! ( TaskEFont = OpenDiskFont( Font )))
return( 5L );
if ( ! ( g = CreateContext( &TaskEGList )))
return( 1L );
for( lc = 0, tc = 0; lc < TaskE_CNT; lc++ ) {
CopyMem((char * )&TaskENGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
TaskEGadgets[ lc ] = g = CreateGadgetA((ULONG)TaskEGTypes[ lc ], g, &ng, ( struct TagItem * )&TaskEGTags[ tc ] );
while( TaskEGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( TaskEMenus = CreateMenus( TaskENewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
return( 3L );
LayoutMenus( TaskEMenus, VisualInfo, TAG_DONE );
if ( ! ( TaskEWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_ACTIVEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, TaskEGList,
WA_Title, TaskEWdt,
WA_ScreenTitle, "Task Exchange",
WA_PubScreen, Scr,
TAG_DONE )))
return( 4L );
SetMenuStrip( TaskEWnd, TaskEMenus );
GT_RefreshWindow( TaskEWnd, NULL );
return( 0L );
}
void CloseTaskEWindow( void )
{
if ( TaskEMenus ) {
ClearMenuStrip( TaskEWnd );
FreeMenus( TaskEMenus );
TaskEMenus = NULL; }
if ( TaskEWnd ) {
CloseWindow( TaskEWnd );
TaskEWnd = NULL;
}
if ( TaskEGList ) {
FreeGadgets( TaskEGList );
TaskEGList = NULL;
}
if ( TaskEFont ) {
CloseFont( TaskEFont );
TaskEFont = NULL;
}
}